package com.qinyunkj.searchchatserver.controller;

import com.qinyunkj.searchchatserver.model.common.Result;
import com.qinyunkj.searchchatserver.model.entity.SysConfig;
import com.qinyunkj.searchchatserver.model.request.ConfigUpdateRequest;
import com.qinyunkj.searchchatserver.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "系统配置")
@RestController
@RequestMapping("/api/sys/config")
@RequiredArgsConstructor
@Validated
public class SysConfigController {

    private final SysConfigService sysConfigService;

    @Operation(summary = "获取所有配置")
    @GetMapping
    public Result<List<SysConfig>> listAll() {
        return Result.success(sysConfigService.list());
    }

    @Operation(summary = "获取配置值")
    @GetMapping("/{key}")
    public Result<String> getConfig(@PathVariable String key) {
        return Result.success(sysConfigService.getConfigValue(key));
    }

    @Operation(summary = "更新配置")
    @PutMapping
    public Result<Void> updateConfig(@Valid @RequestBody ConfigUpdateRequest request) {
        sysConfigService.updateConfig(request.getConfigKey(), request.getConfigValue());
        return Result.success(null);
    }
} 